home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tools / instcopy.tcl < prev    next >
Encoding:
Text File  |  1993-11-19  |  3.4 KB  |  116 lines

  1. #
  2. # instcopy.tcl -- 
  3. #
  4. # Tcl program to copy files during the installation of Tcl.  This is used
  5. # because "copy -r" is not ubiquitous.  It also adds some minor additional
  6. # functionallity.
  7. #
  8. #------------------------------------------------------------------------------
  9. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  10. #
  11. # Permission to use, copy, modify, and distribute this software and its
  12. # documentation for any purpose and without fee is hereby granted, provided
  13. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  14. # Mark Diekhans make no representations about the suitability of this
  15. # software for any purpose.  It is provided "as is" without express or
  16. # implied warranty.
  17. #------------------------------------------------------------------------------
  18. # $Id: instcopy.tcl,v 3.0 1993/11/19 07:00:03 markd Rel $
  19. #------------------------------------------------------------------------------
  20. #
  21. # It is run in the following manner:
  22. #
  23. #  instcopy file1 file2 ... targetdir
  24. #  instcopy -dirname file1 targetdir
  25. #
  26. #  o -dirname - If specified, then a directory is copies as the target
  27. #     directory rather than to it.
  28. #  o files - List of files to copy. If one of directories are specified, they
  29. #    are copied.
  30. #  o targetdir - Target directory to copy the files to.  If the directory does
  31. #    not exist, it is created (including parent directories).
  32. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  33.  
  34. #------------------------------------------------------------------------------
  35. # Usage --
  36. #
  37. #   Issue a usage message and exit.
  38. #------------------------------------------------------------------------------
  39. proc Usage {{msg {}}} {
  40.     if {"$msg" != ""} {
  41.         puts stderr "Error: $msg"
  42.     }
  43.     puts stderr {usage: instcopy ?-dirname? file1 file2 ... targetdir}
  44.     exit 1
  45. }
  46.  
  47. #------------------------------------------------------------------------------
  48. # DoACopy --
  49. #
  50. #------------------------------------------------------------------------------
  51.  
  52. proc DoACopy {file targetDir} {
  53.     global dirNameMode
  54.  
  55.     if [file isdirectory $file] {
  56.         if $dirNameMode {
  57.             set target $targetDir
  58.         } else {
  59.             set target $targetDir/[file tail $file]
  60.         }
  61.         puts stdout ""
  62.         puts stdout "Copying directory hierarchy $file to $target"
  63.         puts stdout ""
  64.         if ![file exists $target] {
  65.             mkdir -path  $target
  66.         }
  67.         CopyDir $file $target
  68.     } else {
  69.         puts stdout ""
  70.         puts stdout "Copying $file to $targetDir"
  71.         puts stdout ""
  72.         CopyFile $file $targetDir
  73.     }
  74. }
  75.  
  76.  
  77. #------------------------------------------------------------------------------
  78. # Main program code.
  79. #------------------------------------------------------------------------------
  80.  
  81. #
  82. # Parse the arguments
  83. #
  84. if {$argc < 2} {
  85.     Usage "Not enough arguments"
  86. }
  87.  
  88. set dirNameMode 0
  89. if {[lindex $argv 0] == "-dirname"} {
  90.     lvarpop argv
  91.     incr argc -1
  92.     set dirNameMode 1
  93. }
  94.  
  95. set files [lrange $argv 0 [expr $argc-2]]
  96. set targetDir [lindex $argv [expr $argc-1]]
  97.  
  98. if {[file exists $targetDir] && ![file isdirectory $targetDir]} {
  99.    Usage "Target is not a directory: $targetDir"
  100. }
  101.  
  102. umask 022
  103.  
  104. if [catch {
  105.     if ![file exists $targetDir] {
  106.         mkdir -path $targetDir
  107.     }
  108.     foreach file $files {
  109.         DoACopy $file $targetDir
  110.     }
  111. } msg] {
  112.     puts stderr "Error: $msg"
  113.     exit 1
  114. }
  115.